<script setup>
import {
  Edit,
  Delete,
  Close
} from '@element-plus/icons-vue'


import { ref } from 'vue'

const queryTime = ref([])



const name = ref('')

//文章列表数据模型
const historyData = ref([

])

//分页条数据模型
const pageNum = ref(1)//当前页
const total = ref(20)//总条数
const pageSize = ref(15)//每页条数

//当每页条数发生了变化，调用此函数
const onSizeChange = (size) => {
  pageSize.value = size
  historyDataList()
}
//当前页码发生变化，调用此函数
const onCurrentChange = (num) => {
  pageNum.value = num
  historyDataList()
}

const types = ref([
  {
    "id": 0,
    "contentValue": "黑",
  },
  {
    "id": 1,
    "contentValue": "白",
  },

])

const memberTypes = ref([
  {
    "id": 0,
    "resourceValue": "普通用户",
  },
  {
    "id": 1,
    "resourceValue": "月会员",
  }
  ,
  {
    "id": 2,
    "resourceValue": "半年会员",
  }
  ,
  {
    "id": 3,
    "resourceValue": "年会员",
  }
])


const type = ref('')




const versionSeasons = ref([


])


import {
  resourceMemberOrderEditService,
  resourceMemberOrderListService
} from '@/api/resourceMemberOrder.js'



import { Plus } from '@element-plus/icons-vue'
import { QuillEditor } from '@vueup/vue-quill'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
//控制抽屉是否显示
const visibleDrawer = ref(false)
//添加表单数据模型
const dataModel = ref({
  type:1
})


//导入token
import { useTokenStore } from '@/stores/token.js';
const tokenStore = useTokenStore();


//上传成功的回调函数
const uploadSuccess = (result) => {
  dataModel.value.imgUrl = result.data;
  console.log(result.data);
}

const uploadAudioSuccess = (result) => {
  dataModel.value.audioUrl = result.data;
  console.log(result.data);
}


//添加文章
import { ElMessage } from 'element-plus'
import {userPointEditListService, userPointListService} from "@/api/userPoint.js";

//编辑分类
const userPointEdit = async () => {
  //调用接口
  let result = await userPointEditListService(dataModel.value);

  ElMessage.success(result.msg ? result.msg : '修改成功')

  //调用获取所有分类的函数
  historyDataList();

  //隐藏弹窗
  visibleDrawer.value = false;
}
type.value=0;


//获取文章列表数据
const historyDataList = async () => {

  let params = {
    pageNum: pageNum.value,
    pageSize: pageSize.value,
    account:account.value ?account.value:null,
    name:name.value ?name.value:null,
  }
  let result = await userPointListService(params);
  //渲染视图
  total.value = result.data.total;
  historyData.value = result.data.records;


}

const orderNo = ref('')

const account = ref('')

const imei = ref('')

const traceKey = ref('')


historyDataList();
const uploadHeadPicSuccess = (result) => {
  dataModel.value.backgroundUrl = result.data.fileUrl;
}
const delHeadPicImg = () => {
  dataModel.value.backgroundUrl = '';
}



//定义变量,控制标题的展示
const title = ref('')
const showUserPoint = (row) => {
  visibleDrawer.value = true, title.value = '编辑信息'
  dataModel.value.account =row.appUserVo.account;
  dataModel.value.name =row.appUserVo.name;
  dataModel.value.level =row.level;
  dataModel.value.userId = row.appUserVo.id;
  dataModel.value.targetLevel='';
  dataModel.value.memberType=row.appUserVo.memberType;

}

//清空模型的数据


</script>
<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>用户积分管理</span>
      </div>
    </template>
    <!-- 搜索表单 -->
    <el-form inline>
      <el-form-item label="账户：">
        <el-input  v-model="account" />
      </el-form-item>
      <el-form-item label="名称：">
        <el-input  v-model="name" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="historyDataList">搜索</el-button>
        <el-button @click="account=''; name=''">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 文章列表 -->
    <el-table :data="historyData" border style="width: 100%">

      <el-table-column label="序号" prop="id"  width="100"></el-table-column>
      <el-table-column label="用户id" prop="appUserVo.userId"  width="100"></el-table-column>
      <el-table-column label="账号" prop="appUserVo.account"   ></el-table-column>
      <el-table-column label="名称" prop="appUserVo.name"   ></el-table-column>
      <el-table-column label="用户积分" prop="pointNum"   ></el-table-column>
      <el-table-column label="用户等级" prop="level"   ></el-table-column>
      <el-table-column label="会员类型">
        <template v-slot="scope">
          <span v-if="scope.row.appUserVo.memberType==0">普通用户</span>
          <span v-if="scope.row.appUserVo.memberType==1">月会员</span>
          <span v-if="scope.row.appUserVo.memberType==2">半年会员</span>
          <span v-if="scope.row.appUserVo.memberType==3">年会员</span>
          <span v-else ></span>
        </template>
      </el-table-column>
      <el-table-column label="会员过期时间" prop="expireTime" ></el-table-column>
      <el-table-column label="操作"  width="150px">
        <template #default="{ row }">
          <el-button :icon="Edit" circle plain type="primary" @click="showUserPoint(row)"></el-button>

        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>
    <!-- 分页条 -->
    <el-pagination v-model:current-page="pageNum" v-model:page-size="pageSize" :page-sizes="[3, 5, 10, 15]"
                   layout="jumper, total, sizes, prev, pager, next" background :total="total" @size-change="onSizeChange"
                   @current-change="onCurrentChange" style="margin-top: 20px; justify-content: flex-end" />





    <!-- 抽屉 -->
    <el-drawer v-model="visibleDrawer" :title="title" direction="rtl" size="50%">
      <!-- 添加文章表单 -->
      <el-form :model="dataModel" label-width="100px">
        <el-form-item label="账号:" >
          <span>{{ dataModel.account }}</span>
        </el-form-item>

        <el-form-item label="名称:" >
          <span>{{ dataModel.name }}</span>
        </el-form-item>

        <el-form-item label="当前等级:" >
          <span>{{ dataModel.level }}</span>
        </el-form-item>

        <el-form-item label="修改等级为:" >
          <el-input-number :min="1" v-model="dataModel.targetLevel" />
        </el-form-item>
        <el-form-item label="会员类型：">
          <el-select placeholder="请选择" v-model="dataModel.memberType">
            <el-option v-for="c in memberTypes" :key="c.id" :label="c.resourceValue" :value="c.id">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="userPointEdit()">保存</el-button>

        </el-form-item>
      </el-form>
    </el-drawer>


  </el-card>
</template>
<style lang="scss" scoped>
.page-container {
  min-height: 100%;
  box-sizing: border-box;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
}


/* 抽屉样式 */
.avatar-uploader {
  :deep() {
    .avatar {
      width: 178px;
      height: 178px;
      display: block;
    }

    .el-upload {
      border: 1px dashed var(--el-border-color);
      border-radius: 6px;
      cursor: pointer;
      position: relative;
      overflow: hidden;
      transition: var(--el-transition-duration-fast);
    }

    .el-upload:hover {
      border-color: var(--el-color-primary);
    }

    .el-icon.avatar-uploader-icon {
      font-size: 28px;
      color: #8c939d;
      width: 178px;
      height: 178px;
      text-align: center;
    }
  }
}

.editor {
  width: 100%;

  :deep(.ql-editor) {
    min-height: 200px;
  }
}
</style>